<template>
  <div class="app-container table">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="表格名称：" prop="tableName">
        <el-input
          v-model="queryParams.tableName"
          placeholder="请输入表格名称"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="表格名称" align="center" prop="tableName" :show-overflow-tooltip="true"/>
      <el-table-column label="表格类型" align="center" prop="tableType" :show-overflow-tooltip="true"/>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"
                       :formatter="row => dateFormatter(row, 'createTime')"></el-table-column>
      <el-table-column label="上次修改" align="center" prop="updateTime" width="180"
                       :formatter="row => dateFormatter(row, 'updateTime')"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-view"
          >预览
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <Dialog title="新增表格"
            width="45%"
            :visible.sync="visible"
            @cancel="cancel"
            @confirm="confirm"
            @updateVisible="val => updateVisible(val, 'visible')">

    </Dialog>

  </div>
</template>

<script>
  import {getTableList, addTableList} from "@/api/tool/table";
  import Dialog from '@/components/Dialog'

  export default {
    name: "index",
    components: {Dialog},
    data() {
      return {
        // 遮罩层
        loading: false,
        // 显示搜索条件
        showSearch: true,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 表格数据
        tableList: [],
        // 新增表格弹框
        visible: false
      }
    },
    created() {
      this.getList()
    },
    methods: {
      /** 查询 */
      handleQuery() {

      },
      /** 重置表单 */
      resetQuery() {

      },
      /** 新增表格 */
      handleAdd() {
        this.visible = true
      },
      /** 删除表格 */
      handleDelete(row) {

      },
      /** 获取表格数据 */
      getList() {
        getTableList(this.queryParams).then(res => {
          this.tableList = res.rows
          this.total = res.total
        })
      },
      /** 表格select切换 */
      handleSelectionChange(selection) {

      },
      /** 标记表格 */
      handleUpdate(row) {

      },
      /** 对话框取消按钮 */
      cancel() {

      },
      /** 对话框确认按钮 */
      confirm() {

      }
    }
  }
</script>

<style scoped lang="scss">
  .table {

  }
</style>
